package prictice.userVisit;

import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.BasicOutputCollector;
import org.apache.storm.topology.IBasicBolt;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;

import java.util.Map;

/**
 * @Package prictice.userVisit
 * @Description:
 * @Author elwyn
 * @Date 2017/9/16 17:00
 * @Email elonyong@163.com
 */
public class FmtLogBolt implements IBasicBolt {

    private static final long serialVersionUID = -8035694857817920707L;

    @Override
    public void prepare(Map map, TopologyContext topologyContext) {

    }

    String eachLog = null;

    @Override
    public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
        eachLog = tuple.getString(0);
        if (eachLog != null && eachLog.length() > 0) {
            basicOutputCollector.emit(new Values(eachLog.split("\t")[2], eachLog.split("\t")[1]));
        }
    }

    @Override
    public void cleanup() {

    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
        outputFieldsDeclarer.declare(new Fields("date", "session_id"));
    }

    @Override
    public Map<String, Object> getComponentConfiguration() {
        return null;
    }
}
